package ac.technion.StreamMania;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * class extending LinearLayout which allows the text used in the layout (which
 * is later used for the iconified list) to be set along with whatever
 * drawable we want next to it.
 */
public class IconifiedTextView extends LinearLayout{
	private TextView mText;
	private ImageView mIcon;
	
	/**
	 * Creates the view for the iconified text - sets the view parameters,
	 * including context, orientation, drawables, padding and text.  Organizes
	 * the view so that the icon will be before the text with a predefined padding
	 * between them.
	 * @param context - the context for this view.
	 * @param aIconifiedText - IconifiedText defining this view - holds the required
	 * drawable and text.
	 */
	public IconifiedTextView(Context context, IconifiedText aIconifiedText) {
		super(context);

		/* First Icon and the Text to the right (horizontal),
		 * not above and below (vertical) */
		this.setOrientation(HORIZONTAL);
		mIcon = new ImageView(context);
		mIcon.setImageDrawable(aIconifiedText.getIcon());
		// left, top, right, bottom
		mIcon.setPadding(0, 1, 5, 1); // 5px to the right
		
		/* At first, add the Icon to ourself
		 * (! we are extending LinearLayout) */
		addView(mIcon,  new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		
		mText = new TextView(context);
		mText.setText(aIconifiedText.getText());
		mText.setTextSize(18);
		mText.setPadding(0,10, 0,0);
	
		/* Now the text (after the icon) */
		addView(mText, new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
	}

	/**
	 * sets the text for this view.
	 * @param words - the text to be used in this view
	 */
	public void setText(String words) {
		mText.setText(words);
	}
	
	/**
	 * sets the icon for this view.
	 * @param bullet - the drawable to be used in this view.
	 */
	public void setIcon(Drawable bullet) {
		mIcon.setImageDrawable(bullet);
	}
}
